package com.bds.btcdc.web.action;

import javax.annotation.Resource;

import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bds.btcdc.api.model.Result;
import com.bds.btcdc.web.service.UserService;
import com.bds.btcdc.web.utils.Const;


@Controller
public class RegisterAction extends BaseAction {
    @Resource
    private UserService userService;

    @RequestMapping("/register/submit")
    @ResponseBody
    public Object signUp(String username,String password,String email,String callback) {
        boolean sign=userService.signUp(username,password,email);
        Result rst=new Result();
        if (sign){
            rst.setResult(Const.SUC,"注册成功,请登录");
        }else{
            rst.setResult(Const.FAIL,"用户名已存在");
        }
        if(callback!=null&&!callback.equals("")){
            MappingJacksonValue value=new MappingJacksonValue(rst);
            value.setJsonpFunction(callback);
            return value;
        }
        return rst;
    }

}
